<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="java.util.*,java.io.*,java.sql.*,java.text.*, dbAccess.*"%>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content
-Type" content="text/html; charset=ISO-8859-1" />
<title>Staff Create/Update Process</title>
<link rel="stylesheet" type="text/css" href="css_files/style.css" />
</head>
<body>
 <%
 
 	//create new doctor
 	Staff newStaff = new Staff(session.getAttribute("Name").toString());
 	String action = request.getParameter("action");
 	
 	if ((action!= null) && action.equals("update"))
 	{

 	 	int staffId = Integer.parseInt(request.getParameter("staffId"));
 		newStaff.setStaffId(staffId);
		DbAccess access = new DbAccess();
		String query = "select SIN from tbl_staff where (StaffId = " + staffId ;
				query += ") and IsDeleted = '0' ";
		
		String SIN = access.ExecuteScalar(access.connect(), query);
 		newStaff.setSIN(Integer.parseInt(SIN));
		newStaff.setPassword(request.getParameter("Password"));

 	}
 	if ((action != null) && (action.equals("add")))
 	{
		newStaff.setSIN(Integer.parseInt(request.getParameter("SIN")));
		newStaff.setPassword(request.getParameter("password"));
 	}

  
  //tbl_doctor
   //out.print(request.getParameter("docSIN"));
   //newDoc.setSIN(Integer.parseInt(request.getParameter("docSIN")));
   newStaff.setFirstName(request.getParameter("firstName"));
   newStaff.setLastName(request.getParameter("lastName"));
   newStaff.setPhoneNum(request.getParameter("phone"));
   newStaff.setHomeAddress(request.getParameter("homeAddress"));
   newStaff.setEmailAddress(request.getParameter("emailAddress"));
   newStaff.setPassword(request.getParameter("password"));
   
   String doctorId = request.getParameter("cmbDoctor").toString();
   doctorId = doctorId.substring(doctorId.indexOf("-")+1);
   
   newStaff.setDocId(Integer.parseInt(doctorId));
   //newStaff.setPassword(request.getParameter("password"));
   
   
   //tbl_doctor
  newStaff.setDateOfBirth((java.sql.Date.valueOf(request.getParameter("dateOfBirth").toString())));
  if (request.getParameter("gender").equals("male"))
  {
  	newStaff.setGender("M");
  }
  else
  {
 	newStaff.setGender("F");
  }
  //String Gender = request.getParameter("frmGender");
  
  if (newStaff.registerStaff(action))
  {
 	 out.print(newStaff.getStatusMsg());
 	 newStaff.setStatusMsg("");
  }
  else
  {
  	out.print("Failed to create Doctor: " + newStaff.getStatusMsg());
  	newStaff.setStatusMsg("");
  }
  
  
  //String backHome = request.getParameter("callerId").toString() + ".jsp";
 %>
 <form id="frmback" action="adminHome.jsp">
 <input type="submit"  name="cmdStaffHome" id="cmdStaffHome" value="Back Home"/>
 </form>

</body>
</html>